/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SLE_CONNECT_PARCEL_H
#define SLE_CONNECT_PARCEL_H

#include <cstdint>
#include <memory>
#include "parcel.h"
#include "sle_address_parcel.h"
#include "sle_connect_config.h"
#include "sle_error_code.h"

namespace OHOS {
namespace NearLink {
namespace SleStandard {
class SleConnectionParam : public Parcelable {
public:
    SleConnectionParam() = default;
    explicit SleConnectionParam(const SleConnectParam &param);
    ~SleConnectionParam() = default;

    bool Marshalling(Parcel &parcel) const override;
    static SleConnectionParam *Unmarshalling(Parcel &parcel);
    bool ReadFromParcel(Parcel &parcel);

    void ConvertToSleConnectParam(SleConnectParam &param) const;
    static SleErrorCode CheckConnectParam(const SleConnectParam &param);

public:
    uint16_t intervalMin_;
    uint16_t intervalMax_;
    uint16_t latency_;
    uint16_t supervisionTimeout_;
};

class SleAuthenticationInfo : public Parcelable {
public:
    SleAuthenticationInfo() = default;
    explicit SleAuthenticationInfo(const SleAuthInfo &info);
    ~SleAuthenticationInfo() = default;

    bool Marshalling(Parcel &parcel) const override;
    static SleAuthenticationInfo *Unmarshalling(Parcel &parcel);
    bool ReadFromParcel(Parcel &parcel);

    void ConvertToSleAuthInfo(SleAuthInfo &info) const;

public:
    uint8_t linkKey_[SLE_LINK_KEY_LEN];
    uint8_t cryptoAlgoType_;
    uint8_t keyDerivAlgoType_;
    uint8_t integrChkInd_;
};

class SleConnectDevice : public Parcelable {
public:
    SleConnectDevice() = default;
    explicit SleConnectDevice(const SleConnectDev &device);
    ~SleConnectDevice() = default;

    bool Marshalling(Parcel &parcel) const override;
    static SleConnectDevice *Unmarshalling(Parcel &parcel);
    bool ReadFromParcel(Parcel &parcel);

    void ConvertToSleConnectDev(SleConnectDev &device) const;

public:
    uint16_t connectId_;
    SleAddress address_;
};
} // SleStandard
} // NearLink
} // OHOS

#endif // SLE_CONNECT_PARCEL_H